package com.learn.swagger.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @author PC
 */
@Configuration
@EnableSwagger2
public class CusSwaggerConfig {
    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .paths(PathSelectors.any())
                .build();
    }

    /**
     * 用于定义API主界面的信息，比如可以声明所有的API的总标题、描述、版本
     *
     * @return api信息
     */
    private ApiInfo apiInfo() {

        Contact contact = new Contact(
                "wm",
                "https://www.***.com",
                "***@qq.com");

        return new ApiInfoBuilder()
                //标题
                .title("swagger")
                //描述
                .description("Swagger文档")
                //版本
                .version("1.0")
                .contact(contact)
                .build();
    }
}

